#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include "server.h"

int log_out (int sock_fd)
{
	int tmp;
	char name[NAME_LEN_MAX + 1];
	
	recv(sock_fd, &tmp, sizeof(int), 0);
	memset(name, 0, NAME_LEN_MAX);
	recv(sock_fd, name, tmp, 0);
	
	user *u = get_user(name);
	if ( u == NULL) 
	{
		tmp = -1;
		send(sock_fd, &tmp, sizeof(int), 0);
	} 
	else
	{
		u->sock_fd = -1;
		u->sock_fd2 = -1;
		tmp = 0;
		send(sock_fd, &tmp, sizeof(int), 0);
	}
	printf("res:\t%d\n", tmp);
}
